/*    */package imageViewer;

/*    */
/*    */import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import javafx.application.Platform;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.scene.shape.Rectangle;

/*    */
/*    */class Thumbnail extends StackPane
/*    */{
	/* 18 */private final Double size = Double.valueOf(50.0D);
	/* 19 */private final Double imageSize = Double.valueOf(100.0D);
	/*    */private final String urlToImage;
	/*    */private final Label imageLabel;
	/* 23 */private boolean loaded = false;

	/*    */
	/*    */public Thumbnail(String urlToImage)
	/*    */{
		/* 28 */this.urlToImage = urlToImage;
		/*    */
		/* 30 */setAlignment(Pos.CENTER);
		/*    */
		/* 32 */ImageView loading = new ImageView(new Image(
				Thumbnail.class.getResourceAsStream("/loading.gif")));
		/*    */
		/* 35 */this.imageLabel = new Label();
		/*    */
		/* 37 */this.imageLabel.setGraphic(loading);
		/* 38 */this.imageLabel.setAlignment(Pos.CENTER);
		/* 39 */setMinSize(this.size.doubleValue(), this.size.doubleValue());
		/* 40 */setMaxSize(this.size.doubleValue(), this.size.doubleValue());
		/*    */
		/* 42 */this.imageLabel.setMinSize(this.size.doubleValue() - 2.0D,
				this.size.doubleValue() - 2.0D);
		/* 43 */this.imageLabel.setMaxSize(this.size.doubleValue() - 2.0D,
				this.size.doubleValue() - 2.0D);
		/*    */
		/* 45 */Rectangle rectangle = new Rectangle();
		/* 46 */rectangle.setWidth(this.size.doubleValue() - 2.0D);
		/* 47 */rectangle.setHeight(this.size.doubleValue() - 2.0D);
		/* 48 */this.imageLabel.setClip(rectangle);
		/*    */
		/* 50 */Rectangle rectangle2 = new Rectangle();
		/* 51 */rectangle2.setWidth(50.0D);
		/* 52 */rectangle2.setHeight(50.0D);
		/* 53 */setClip(rectangle2);
		/*    */
		/* 55 */getChildren().add(this.imageLabel);
		/*    */
		/* 57 */getStyleClass().add("thumbnail");
		/*    */}

	/*    */
	/*    */public void init()
	/*    */{
		/* 62 */if (!this.loaded) {
			/* 63 */this.loaded = true;
			/* 64 */new Thread()
			/*    */{
				/*    */public void run()
				/*    */{
					/*    */try
					/*    */{
						/* 74 */URL url = new URL(Thumbnail.this.urlToImage);
						/* 75 */HttpURLConnection connection = (HttpURLConnection) url
								.openConnection();
						/*    */
						/* 77 */InputStream inputStream = connection
								.getInputStream();
						/* 78 */final byte[] image = Gallery
								.toByteArray(inputStream);
						/* 79 */inputStream.close();
						/* 80 */connection.disconnect();
						/*    */
						/* 82 */Platform.runLater(new Runnable()
						/*    */{
							/*    */public void run()
							/*    */{
								/* 87 */Image thumbnail = new Image(
										new ByteArrayInputStream(image));
								/*    */
								/* 90 */ImageView iv = new ImageView(thumbnail);
								/* 91 */iv
										.setFitHeight(Thumbnail.this.imageSize
												.doubleValue());
								/* 92 */iv.setFitWidth(Thumbnail.this.imageSize
										.doubleValue());
								/* 93 */iv.setSmooth(true);
								/* 94 */iv.setPreserveRatio(true);
								/*    */
								/* 96 */Thumbnail.this.imageLabel
										.setGraphic(iv);
								/* 97 */Thumbnail.this.getStyleClass().add(
										"loaded");
								/*    */}
						});
						/*    */}
					/*    */catch (Exception e1) {
						/* 101 */e1 =
						/* 103 */e1;
						/*    */}
					/*    */finally
					/*    */{
						/*    */}
					/*    */}
				/*    */
			}
			/* 64 */.start();
			/*    */}
		/*    */}
	/*    */
}

/*
 * Location: /media/store/Development/lab/imageGallery/ Qualified Name:
 * es.carlosmontero.javafx.gallery.Thumbnail JD-Core Version: 0.6.2
 */